const webpack = require('webpack');
const postcssImporter = require('postcss-import');
const autoprefixer = require('autoprefixer');
const postcssOpacity = require('postcss-opacity');

const hot = ['webpack-hot-middleware/client?noInfo=true&reload=true']

module.exports = {
  entry: {
    'jquery-3.2.1.min': hot.concat(['./src/js/jquery-3.2.1.min.js']),
    login: hot.concat(['./src/js/login.js']),
    main: hot.concat(['./src/js/main.js']),
    tableExporter: hot.concat(['./src/js/tableExporter.js']),
  },

  output: {
    path: '/',
    publicPath: '/',
    filename: 'js/[name].js',
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'buble-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              sourceMap: true,
            }
          },
          'postcss-loader'
        ]
      },
      {
        test: /\.(png|jpg|gif|eot|woff2|woff|ttf|svg)$/,
        loader: 'url-loader',
        // options: {
        //   sourceMap: true,
        //   limit: 1000,
        //   name: 'images/[name].[ext]?[hash:7]',
        // },
      },
    ],
  },

  plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        postcss: [
          postcssImporter(),
          autoprefixer(),
          postcssOpacity(),
        ],
        context: __dirname,
      },

    }),

    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin()
  ],
};
